﻿using CatUtils.Utils.Currency;
using CatUtils.Utils.Currency.TextUtils;
using System;
using System.Collections.Generic;

namespace RabbitDownload.WebSite.Konachan.ALL
{
    internal class KonachanAllScanner
    {
        public void Start(string StartPage, string EndPage, string API, string Rating, string Score, bool OpenExclude, bool OpenLog)
        {
            int StartCount = TextHelper.StringToInt(StartPage);
            int EndCount = TextHelper.StringToInt(EndPage);
            int ScoreCount = TextHelper.StringToInt(Score);
            if (EndCount < StartCount || StartCount == 0)
            {
                Console.WriteLine("起始页小于结束页");
                return;
            }

            List<string> AllFileList = GetArticleList(StartCount, EndCount, API, Rating, ScoreCount, OpenExclude, OpenLog);
            WebCurrency.SaveHelper.AutoSave(AllFileList, "Konachan", "ALL");
        }

        /// <summary>
        /// 获取文件列表
        /// </summary>
        /// <param name="StartCount"></param>
        /// <param name="EndCount"></param>
        /// <param name="API"></param>
        /// <param name="OpenExclude"></param>
        /// <param name="OpenLog"></param>
        /// <returns></returns>
        private List<string> GetArticleList(int StartCount, int EndCount, string API, string Rating, int Score, bool OpenExclude, bool OpenLog)
        {
            List<string> TempList = new List<string>();
            for (; StartCount <= EndCount; StartCount++)
            {
                Console.WriteLine("第{0}页正在扫描", StartCount);
                TempList.AddRange(new KonachanTool().GetImgList(string.Format(API, StartCount), Rating, Score, OpenExclude, OpenLog));
            }
            return TempList;
        }
    }
}